package com.tangsm.spring.mvc.mybatis.controller;

import com.tangsm.spring.mvc.mybatis.domain.entity.NestPerson;
import com.tangsm.spring.mvc.mybatis.domain.entity.Person;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 实体验证
 */
@RestController
@RequestMapping("/valid")
public class ValidController {

    /**
     * 测试 @Valid对JavaBean的校验效果
     *
     * @param person
     * @return
     */
    @RequestMapping("/valid")
    public String testValid(@Valid @RequestBody Person person) {
        System.out.println(person);
        return "OK";
    }

    /**
     * 测试 @Validated对JavaBean的校验效果
     *
     * @param person
     * @return
     */
    @RequestMapping("/validated")
    public String testValidated(@Validated @RequestBody Person person) {
        System.out.println(person);
        return "OK";
    }

    /**
     * 测试 @Valid对JavaBean嵌套属性的校验效果
     *
     * @param person
     * @return
     */
    @RequestMapping("/validNest")
    public String testValid(@Valid @RequestBody NestPerson person) {
        System.out.println(person);
        return "OK";
    }

    /**
     * 测试 @Validated对JavaBean嵌套属性的校验效果
     *
     * @param person
     * @return
     */
    @RequestMapping("/validatedNest")
    public String testValidated(@Validated @RequestBody NestPerson person) {
        System.out.println(person);
        return "OK";
    }
}
